package com.cangxuan.backend.service.impl;

import com.cangxuan.backend.dao.IBillDao;
import com.cangxuan.backend.entity.User;
import com.cangxuan.backend.entity.UserAmountRecord;
import com.cangxuan.backend.service.IBillService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author: 彭伟辰
 * 流水接口实现
 */
@Service
public class BillServiceImpl extends BaseServiceImpl implements IBillService {
    IBillDao billDao;

    public IBillDao getBillDao() {
        return billDao;
    }

    @Autowired
    public void setBillDao(IBillDao billDao) {
        this.billDao = billDao;
    }

    @Override
    public List<UserAmountRecord> selectWhole(String year, String month, Integer state) {
        List<UserAmountRecord> billList;
        User currentUser = getCurrentUser();
        int userId=currentUser.getId();
        if(state>-1){
            billList=billDao.selectIncome(userId,year,month,state);
        }else {
            billList=billDao.selectWhole(userId,year,month);
        }
        return billList;
    }

    @Override
    public Float selectTotal(String year, String month, byte direction) {
        User currentUser = getCurrentUser();
        int userId=currentUser.getId();
        Float aFloat = billDao.selectTotal(userId, year, month, direction);
        return aFloat==null?0:aFloat;
    }


}
